/**
 * Created by ling on 2017/3/20.
 * 数据字典新增js
 */
$(document).ready(function () {
    //VUE数据绑定对象
    var addValuesVue = null;
    var pid = app.getUrlParam("PID");
    //取出url中的ID
    var para_Id = app.getUrlParam('ID');
    //定义请求连接
    var callUrl = '';
    //判断ID是否为空，如果为空则是新增，不为空则为修改
    if (para_Id != null && para_Id != '') {
        //修改操作
        callUrl = '../../../../api/BaseDictionaryController/update';
        //根据ID获取实体数据
        var result = app.callAjaxPostSync("../../../../api/BaseDictionaryController/selectByID", {ID: para_Id});
        addValuesVue = new Vue({
            el: '#dictionaryAddView',
            data: {
                myParams: result.data[0]
            }
        });
    } else {
        //新增界面
        var callMaxSeq = app.callAjaxPostSync("../../../../api/BaseDictionaryController/selectMaxSeqByPID", {PID: pid});

        callUrl = '../../../../api/BaseDictionaryController/insert';
        addValuesVue = new Vue({
            el: '#dictionaryAddView',
            data: {
                myParams: {
                    PARACODE: '',//编号
                    PARANAME: '',//名称
                    SEQUENCE: callMaxSeq.success ? callMaxSeq.data : '',//次序
                    PID: pid
                }
            }
        });
    }
    //新增界面的暂存按钮
    $('#addSaveBtn').bind('click', function () {
        var formValues = {};
        formValues = addValuesVue.myParams;
        var isValid=  $("#dictionaryAddView").valid();
        if(!isValid){
            layer.alert("请填写完整信息",{icon: 0});
            return;
        }
        var loadIndex=loading();
        loadIndex.show();
        app.callAjaxPost(callUrl, formValues, function (result) {
            loadIndex.close();
            if (result.success) {
                //提示是否成功，并且回调关闭当前弹窗
                parent.layer.close(parent.layer.getFrameIndex(window.name)); //再执行关闭
                parent.layer.alert(result.message, {icon: 1});
            } else {
                layer.alert(result.message, {icon: 2});
            }
        }, this);
    });
});

